
import os
import pytest

from langchain_openai import ChatOpenAI
from browser_use import Agent
from dotenv import load_dotenv
# 加载环境变量
load_dotenv()

llm = ChatOpenAI(
    model='deepseek-ai/DeepSeek-V3',
    api_key=os.getenv('API_KEY'),
    base_url='https://api.siliconflow.cn/v1',
    temperature=0
)

@pytest.mark.asyncio
@pytest.mark.parametrize("username,password,expected", [("fantastic2318@163.com", "1111", "fantastic2318"),("fantastic2318@163.com", "2222", "账号密码输入错误")])
async def test_login(username, password, expected):
    agent = Agent(
        task=f"""
        1、导航到网址:https://mail.163.com/
        2、输入用户名:{username}, 密码:{password}
        3、点击登录按钮
        4、验证是否登录成功,登录成功返回{expected}
        """,
        llm=llm,
        use_vision=False,
    )
    result = await agent.run()
    print(result.final_result())
    assert expected in str(result.final_result())


